﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DataBaseTool
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }

        [DllImport("winmm.dll")]
        public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

        int sec = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            mciSendString("set wave bitpersample 8", "", 0, 0);  //设为8位       
            mciSendString("set wave samplespersec 11025", "", 0, 0);//设置每个声道播放和记录时的样本频率为20Hz-20000Hz
            mciSendString("set wave channels 2", "", 0, 0);  //设为立体声   
            mciSendString("set wave format tag pcm", "", 0, 0);//设置PCM（脉冲编码调制）     
            mciSendString("open new type WAVEAudio alias movie", "", 0, 0); //打开一个新的录音文件        
            mciSendString("record movie", "", 0, 0);  //开始录音
            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            mciSendString("stop movie", "", 0, 0);//停止录音          
            mciSendString("save movie" + " " + "recordvoice.wav", "", 0, 0);//保存录音文件，recordvoice.wav为录音文件       
            mciSendString("close movie", "", 0, 0);   //关闭录音

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            sec++;
            label1.Text = sec.ToString();
        }
    }
}
